import { _HttpClient } from '@delon/theme';
import { Injectable } from '@angular/core';
import { HttpParams, HttpHeaders } from '@angular/common/http';
import { environment } from '../../../../environments/environment';

const responseHeaders = new HttpHeaders().set('Content-Type', 'application/json;charset=UTF-8');

@Injectable({ providedIn: 'root' })
export class ArticleManegeService {
    constructor(private http: _HttpClient, ) { }


    /**
     *  查询列表
     * @param param category: tongzhilan xuexijiaoliu quntuangongzuo
     * @param param title:
     * @param param size:
     * @param param pageNum:
     * @param param startDate:
     * @param param endDate:
     * @param param mid:
     */
    query(param) {
        const dataurl = environment.apiBase + '/csmis/news/findAll/edit.jwt';
        return this.http.get(dataurl, param);
    }
    /**
     *  查询列表
     * @param param category: tongzhilan xuexijiaoliu quntuangongzuo
     * @param param title:
     * @param param size:
     * @param param pageNum:
     * @param param startDate:
     * @param param endDate:
     * @param param mid:
     */
    queryView(param) {
        const dataurl = environment.apiBase + '/csmis/news/findAll/view.jwt';
        return this.http.get(dataurl, param);
    }


    queryAllByCa(param) {
        const dataurl = environment.apiBase + '/csmis/news/index.jwt';
        return this.http.get(dataurl, param);
    }

    /**
     *
     * @param param 种类id：category
     * @param param 内容：content
     * @param param 附件名：fileName(有附件的情况)
     * @param param 附件地址：fileUrll(有附件的情况)
     * @param param id
     * @param param 标题：title
     * @param param 发文时间：operTime (非必填)
     * @param param 文章来源：operOrgId (非必填)
     * @param param 文章来源：operOrgName (非必填)
     */
    save(param) {
        const dataurl = environment.apiBase + '/csmis/news/save.jwt';
        // const headers = new HttpHeaders().set("Content-Type", "application/x-www-form-urlencoded");
        return this.http.post(dataurl, param);
    }

    /**
     * 删除
     * @param ids '[1,2,3]'
     */
    delete(ids) {
        const dataurl = environment.apiBase + '/csmis/news/deletes.jwt';
        return this.http.post(dataurl, '', { ids }, { headers: responseHeaders });
    }

    deleteFile(id) {
        if (!id) {
            return;
        }
        const dataurl = environment.apiBase + '/csmis/news/delFile.jwt';
        return this.http.post(dataurl, '', { id }, { headers: responseHeaders });
    }

    /**
     * 根据文章大类查询二级子类
     * @param dictID tongzhilan  通知栏 xuexijiaoliu 学习交流 quntuangongzuo 群团工作 shouyexinwen 根节点
     */
    getCategory(dictID, isGroup = 0) {
        if (!dictID) {
            return;
        }
        const dataurl = environment.apiBase + '/csmis/probdict/data.jwt?isGroup=' + isGroup;
        return this.http.get(dataurl, { dictID });
    }

    getArticleInfo(id) {
        if (!id) {
            return;
        }
        const dataurl = environment.apiBase + '/csmis/news/findOne.jwt';
        return this.http.get(dataurl, { id });
    }
}
